//
// Created on 2022/11/16.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef XComponent_TextBitmap_H
#define XComponent_TextBitmap_H

#include <native_drawing/drawing_bitmap.h>
#include <native_drawing/drawing_canvas.h>
#include <native_drawing/drawing_text_typography.h>
#include <native_drawing/drawing_font_collection.h>

#define DEFAULT_FONTSIZE 20

class TextBitmap {
public:
    static const int HORIZONTALALIGN_LEFT = 1;
    static const int HORIZONTALALIGN_RIGHT = 2;
    static const int HORIZONTALALIGN_CENTER = 3;

    static const int VERTICALALIGN_TOP = 1;
    static const int VERTICALALIGN_BOTTOM = 2;
    static const int VERTICALALIGN_CENTER = 3;
    static TextBitmap *createCCTextBitmap(const char *text, const char *pFontName, const char * fAlignment,
                                            int width_, int height_, double fontSize);
    ~TextBitmap();
    void *getPixelAddr();
    int GetWidth() { return width; }
    int GetHeight() { return height; }
    int GetBufferSize(){return bufferSize;}

private:
    /**
     * Calculate the start point of x-drawing
     * @param pAlignment Edge settings for text
     * @param layoutWidth Width when text is measured
     * @param realWidth Actual text width
     * @param textWidth Width of the last display of the text control, that is, the width of the bitmap.
     * @return x The starting point of the drawing
     */
    static double calxStartPosition(int pAlignment, int layoutWidth, int realWidth);

    static int processTextAlign(const char * fAlignment);
    void *pixelAddr = nullptr;
    int width = 0;
    int height = 0;
    int bufferSize =0;

    OH_Drawing_Bitmap *_bitmap{nullptr};
    OH_Drawing_Canvas *_canvas{nullptr};
    OH_Drawing_TypographyStyle *_typographyStyle{nullptr};
    OH_Drawing_TypographyCreate *_typographyCreate{nullptr};
    OH_Drawing_FontCollection *_fontCollection{nullptr};
    OH_Drawing_TextStyle *_textStyle{nullptr};
    OH_Drawing_Typography *_typography{nullptr};
    static TextBitmap *createCCTextBitmap(const char *text, const char *pFontName, const float a, const float r,
                                          const float g, const float b, const char *fAlignment, int width_, int height_,
                                          double fontSize);
    static TextBitmap *createCCTextBitmap(const char *text, const char *pFontName, const int pFontSize,
                                          const float fontTintA, const float fontTintR, const float fontTintG,
                                          const float fontTintB, const char *fAlignment, const int pWidth,
                                          const int pHeight, const bool shadow, const float shadowDX,
                                          const float shadowDY, const float shadowBlur, const bool stroke,
                                          const float strokeR, const float strokeG, const float strokeB,
                                          const float strokeSize);
}; 
#endif 
